<%@ page import="java.io.*, java.text.*, java.util.Date, java.sql.*, javax.servlet.*, javax.servlet.http.*, java.util.*" %>

<%
String usernameSC = (String) session.getAttribute("session_name");
String typeSC = (String) session.getAttribute("type");
if(usernameSC == null || typeSC.equals("student") || typeSC.equals("root"))
	response.sendRedirect("error.jsp");
%>

<script language="javascript" type="text/javascript">
var newProject = new Array("","","","","","","","","","");
var previousType = "Description";
var firstS = true;
var firstF = true;
var firstC = true;
function show1(type)
{
	var pre = eval("document.addProject."+previousType);
	pre.value = document.getElementById("txta").value;
	document.getElementById("txta").value = eval("document.addProject."+type+".value");
	document.getElementById(previousType).className = "free";
	document.getElementById(type).className = "choosen";
	previousType = type;
	
}

function openPreviewWindow(x,y,page)
{
	textFill();
	var maxX=screen.width; 
	var maxY= screen.height;
	var wX = window.width;
	var wY = window.height;
	var wdth;
	var heght;
	if(x == 0)
	{
		wdth = maxX - (maxX/4);
		heght = maxY -(maxY/4);
	}
	else
	{
		wdth = x;
		heght = y;
	}	
	window.open(page+".jsp",page,"height="+heght+",width="+wdth+",scrollbar=yes").moveTo((maxX/2)-(wdth/2),(maxY/2)-(heght/2));
	
}
function textFill()
{
	var pre = eval("document.addProject."+previousType);
	pre.value = document.getElementById("txta").value;
}

function addDone()
{
	textFill();
	var div = document.getElementById("errorAdd");
	if(document.addProject.Title.value=="")
	{
		div.innerHTML = "<font style='background-color: white; font-size:12pt' face='Arial' color = 'red'>Your project details are not compelete, please check the title field!</font>";
		
		return false;
	}
	else if(document.addProject.Description.value=="")
	{
		div.innerHTML = "<font style='background-color: white; font-size:12pt' face='Arial' color = 'red'>Your project details are not compelete, please check the description field!</font>";
		
		return false;
	}
	else if(document.addProject.Project_Objectives.value=="")
	{
		div.innerHTML = "<font style='background-color: white; font-size:12pt' face='Arial' color = 'red'>Your project details are not compelete, please check the project objectives field!</font>";
		
		return false;
	}
	else if(document.addProject.Required_Background.value=="")
	{
		div.innerHTML = "<font style='background-color: white; font-size:12pt' face='Arial' color = 'red'>Your project details are not compelete, please check the required background field!</font>";
		
		return false;
	}
	else if(document.addProject.Tools_Needed.value=="")
	{
		div.innerHTML = "<font style='background-color: white; font-size:12pt' face='Arial' color = 'red'>Your project details are not compelete, please check the tools needed field!</font>";
		
		return false;
	}
	else if(document.addProject.Project_Type.value=="")
	{
		div.innerHTML = "<font style='background-color: white; font-size:12pt' face='Arial' color = 'red'>Your project details are not compelete, please check the project type field!</font>";
		
		return false;
	}
	else if(document.addProject.Project_Keywords.value=="")
	{
		div.innerHTML = "<font style='background-color: white; font-size:12pt' face='Arial' color = 'red'>Your project details are not compelete, please check the project keywords field!</font>";
		
		return false;
	}
	else if(document.addProject.Expected_Results.value=="")
	{
		div.innerHTML = "<font style='background-color: white; font-size:12pt' face='Arial' color = 'red'>Your project details are not compelete, please check the expected result field!</font>";
		
		return false;
	}
		
		
	//onfocus="resetError()"
	return true;
}

function resetError()
{
	var div = document.getElementById("errorAdd");
	div.style.bgcolor = "white";
	div.innerHTML = "";
}

function onLoadDo()
{
	var output = "";
	var div = document.getElementById("fsize");
	output ="Font size:<br><SELECT name='fSize' style='' scrollbar=yes><OPTGROUP Label='Font size' onclick='setSize()'>";
	for(var i=8; i <= 36; i+=2)
		output += "<OPTION value="+i+">"+i+"</OPTION>";
	output+= "</OPTGROUP></SELECT>";
	div.innerHTML = ""+output;
}

function setB()
{
		document.getElementById('txta').value += "<b> </b>";
}
function setU()
{
		document.getElementById('txta').value += "<u> </u>";
}
function setI()
{
		document.getElementById('txta').value += "<i> </i>";
}

function setSFC()
{
	var size = document.addProject.fSize.value;
	var style = document.addProject.fStyle.value;
	var color = document.addProject.fColor.value;
	document.getElementById('txta').value += "<font style=\"font-size: "+size+"pt\" face=\""+style+"\" color=\""+color+"\"> </font>";
	
}

</script>
<center>

<form onsubmit= "return addDone()" name= "addProject" method="POST" action="addP.jsp">

<center><table class="Btable" border="0" height= "50%" width="99%" cellspacing="0" cellpadding="0" >
<tr><td align="left" style="color: #000000; font-size: 12pt; padding: 0px" colspan="8"><b>Title:</b>&nbsp;&nbsp;&nbsp;<input style="width:90%; padding: 3px; font-size:12pt; color: #000000" type="text" name= "Title" id= "title">
	</td>
</tr>
<tr>
	<td id="Description" class="choosen" onclick="show1('Description')">Description
	</td>
	<td id="Project_Objectives" class="free" onclick="show1('Project_Objectives')">Project<br>Objectives
	</td>
	<td id="Required_Background" class="free" onclick="show1('Required_Background')">Required<br>Background
	</td>
	<td id="Tools_Needed" class="free" onclick="show1('Tools_Needed')">Tools<br>Needed
	</td>
	<td id="Difficulty_Level" class="free" onclick="show1('Difficulty_Level')">Difficulity<br>Level
	</td>
	<td id="Project_Type" class="free" onclick="show1('Project_Type')">Project<br>Type
	</td>
	<td id="Project_Keywords" class="free" onclick="show1('Project_Keywords')">Project<br>Keywords
	</td>
	<td id="Expected_Results" class="free" onclick="show1('Expected_Results')">Expected<br>Results
	</td>
	<td id="Additional_Comments" class="free" onclick="show1('Additional_Comments')">Additional<br>Comments
	</td>
</tr>	
<tr>
	<td class="tabsbody" align="right">
		<center><br><input style="font-size: 8pt; font-weight: bold" type="button" value=" bold " onclick="setB()"/><center>
	</td>
	<td class="tabsbody" align="right">
		<center><br><input style="font-size: 8pt; font-style: italic" type="button" value="italic" onclick="setI()"/></center>
	</td>
	<td class="tabsbody" align="right">
		<center><br><input style="font-size: 8pt; text-decoration: underline" type="button" value="underline" onclick="setU()"/></center>
	</td>
	
	<td class="tabsbody" colspan="2"><center>
		Font color <SELECT name='fColor'><OPTGROUP Label='Font color'>
		<OPTION style="background-color: black"  value="black">black</OPTION>
		<OPTION style="background-color: blue" value="Blue">Blue</OPTION>
		<OPTION style="background-color: lightblue" value="lightblue">Light blue</OPTION>
		<OPTION style="background-color: darkblue" value="darkblue">Dark blue</OPTION>
		<OPTION style="background-color: cyan" value="cyan">Cyan</OPTION>
		<OPTION style="background-color: green" value="green">Green</OPTION>
		<OPTION style="background-color: lightgreen" value="lightgreen">Light green</OPTION>
		<OPTION style="background-color: darkgreen" value="darkgreen">Dark green</OPTION>
		<OPTION style="background-color: red" value="red">Red</OPTION>
		<OPTION style="background-color: darkred" value="darkred">Dark red</OPTION>
		<OPTION style="background-color: pink" value="pink">Pink</OPTION>
		<OPTION style="background-color: magenta" value="magenta">Magenta</OPTION>
		<OPTION style="background-color: orange" value="orange">Orange</OPTION>
		<OPTION style="background-color: yellow" value="yellow">Yellow</OPTION>
		</OPTGROUP></SELECT></center>
	</td>
		
	<td class="tabsbody" colspan="2"><center>
		Font style <SELECT name='fStyle'><OPTGROUP Label='Font style'>
		<OPTION value="Arial">Arial</OPTION>
		<OPTION value="Times New Roman">Times New Roman</OPTION>
		<OPTION value="Tahoma">Tahoma</OPTION>
		<OPTION value="Courier New">Courier New</OPTION>
		<OPTION value="Andalus">Andalus</OPTION>
		<OPTION value="Arabic Transparent">Arabic Transparent</OPTION>

		</OPTGROUP></SELECT></center>
		</td>
		<td class="tabsbody"><center>
		<div id="fsize">
		</div></center>
		</td>
		<td class="tabsbody"><center>
			<br> <input style =" font-size: 9pt; color: black; font-weight: bold" type="button" value="apply" onclick="setSFC()"/></center>
		</td>
</tr>
<tr height="100%" style=" padding: 0px">
	<td class="tabsbody" colspan="10">
		<br><center><textarea id= "txta" onchange="textFill()" onfocus="textFill()" wrap="soft" style="font-size:12pt; width:95%; background-color: #eef3f7" ROWS="10"></textarea></center><br>
	</td>
</tr>
<tr colspan="10">
	<td>
		<input type="hidden" name="Description"/>
		<input type="hidden" name="Project_Objectives"/>
		<input type="hidden" name="Required_Background"/>
		<input type="hidden" name="Tools_Needed"/>
		<input type="hidden" name="Difficulty_Level"/>
		<input type="hidden" name="Project_Type"/>
		<input type="hidden" name="Project_Keywords"/>
		<input type="hidden" name="Expected_Results"/>
		<input type="hidden" name="Additional_Comments"/>
		
		<INPUT TYPE="button" VALUE="Add Image" onclick="openPreviewWindow(250,70,'upload')"/>
	</td>
</tr>
<tr>
	<td colspan="9">
		<center><input type="button" value ="Preview" onclick="openPreviewWindow(0,0,'preview')"/>&nbsp;<input type="submit" value =" Create new project"/></center>
	</td>
</tr>
	 </table>
</form>
</center>
<div id="errorAdd"></div>